import React,{ReactElement,FC} from 'react';
import {
    Navigate
} from "react-router-dom";

// 1
// function Index(props:any) {
    // if(localStorage.getItem("token")){
    //     return props.children;
    // }
    // return (
    //     <Navigate to={"/login"}></Navigate>
    // )

    // 以上代码优化
    // return localStorage.getItem("token")?props.children:<Navigate to={"/login"}></Navigate>
// }

// 2
// const Index = (props:any)=>localStorage.getItem("token")?props.children:<Navigate to={"/login"}></Navigate>;


// 3
// type TProps = {
//     children:React.ReactElement
// }
// const Index = (props:TProps)=>localStorage.getItem("token")?props.children:<Navigate to={"/login"}></Navigate>;


// 4
// type TProps = {
//     children:React.ReactElement
// }
// const Index:React.FC<TProps> = (props)=>localStorage.getItem("token")?props.children:<Navigate to={"/login"}></Navigate>;

// 5
type TProps = {
    children:ReactElement
}
const Index:FC<TProps> = (props)=>localStorage.getItem("token")?props.children:<Navigate to={"/login"}></Navigate>;

export default Index;